challenge_2
Author

Lai Wei

Published

August 22, 2022

Code
library(tidyverse)

knitr::opts_chunk$set(echo = TRUE, warning=FALSE, message=FALSE)

Challenge Overview

Today’s challenge is to

  1. read in a data set, and describe the data using both words and any supporting information (e.g., tables, etc)
  2. provide summary statistics for different interesting groups within the data, and interpret those statistics

Read in the Data

Read in one (or more) of the following data sets, available in the posts/_data folder, using the correct R package and command.

  • railroad*.csv or StateCounty2012.xlsx ⭐
  • FAOstat*.csv ⭐⭐⭐
  • hotel_bookings ⭐⭐⭐⭐
Code
library(readr)
FAOSTAT_livestock <- read_csv("_data/FAOSTAT_livestock.csv")
View(FAOSTAT_livestock)

Add any comments or documentation as needed. More challenging data may require additional code chunks and documentation.

Describe the data

Using a combination of words and results of R commands, can you provide a high level description of the data? Describe as efficiently as possible where/how the data was (likely) gathered, indicate the cases and variables (both the interpretation and any details you deem useful to the reader to fully understand your chosen data).

Code
#Choose Area columns in FAOSTAT_livestock 
select(FAOSTAT_livestock, starts_with("Area"))
# A tibble: 82,116 × 2
   `Area Code` Area       
         <dbl> <chr>      
 1           2 Afghanistan
 2           2 Afghanistan
 3           2 Afghanistan
 4           2 Afghanistan
 5           2 Afghanistan
 6           2 Afghanistan
 7           2 Afghanistan
 8           2 Afghanistan
 9           2 Afghanistan
10           2 Afghanistan
# … with 82,106 more rows
# ℹ Use `print(n = ...)` to see more rows
Code
#Show the col names in FAOSTAT_livestock
colnames(FAOSTAT_livestock)
 [1] "Domain Code"      "Domain"           "Area Code"        "Area"            
 [5] "Element Code"     "Element"          "Item Code"        "Item"            
 [9] "Year Code"        "Year"             "Unit"             "Value"           
[13] "Flag"             "Flag Description"

Provide Grouped Summary Statistics

Conduct some exploratory data analysis, using dplyr commands such as group_by(), select(), filter(), and summarise(). Find the central tendency (mean, median, mode) and dispersion (standard deviation, mix/max/quantile) for different subgroups within the data set.

Code
#Set Year as the col containing year in FAOSTAT_livestock with first six
Year <- head(select(FAOSTAT_livestock,contains("Year")))
#Make a table of Year 
table(Year)
         Year
Year Code 1961 1962 1963 1964 1965 1966
     1961    1    0    0    0    0    0
     1962    0    1    0    0    0    0
     1963    0    0    1    0    0    0
     1964    0    0    0    1    0    0
     1965    0    0    0    0    1    0
     1966    0    0    0    0    0    1

Explain and Interpret

Be sure to explain why you choose a specific group. Comment on the interpretation of any interesting differences between groups that you uncover. This section can be integrated with the exploratory data analysis, just be sure it is included.